{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### ❇️ Latex for Python 🐍 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "import latexify"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$ \\displaystyle \\mathrm{solve}(a, b, c)\\triangleq \\frac{-b + \\sqrt{b^{2} - 4ac}}{2a} $$"
      ],
      "text/plain": [
       "<latexify.core.with_latex.<locals>._LatexifiedFunction at 0x7fe8c0569cd0>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@latexify.with_latex\n",
    "def solve(a, b, c):\n",
    "  return (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)\n",
    "solve"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$ \\displaystyle \\mathrm{fib}(x)\\triangleq \\left\\{ \\begin{array}{ll} 1, & \\mathrm{if} \\ x=0 \\\\ 1, & \\mathrm{if} \\ x=1 \\\\ \\mathrm{fib}\\left(x - 1\\right) + \\mathrm{fib}\\left(x - 2\\right), & \\mathrm{otherwise} \\end{array} \\right. $$"
      ],
      "text/plain": [
       "<latexify.core.with_latex.<locals>._LatexifiedFunction at 0x7fe8c0685340>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Automatically unrolls Elif or nested else-if ⬇️ 💥 \n",
    "\n",
    "@latexify.with_latex\n",
    "def fib(x):\n",
    "  if x == 0:\n",
    "    return 1\n",
    "  elif x == 1:\n",
    "    return 1\n",
    "  else:\n",
    "    return fib(x-1) + fib(x-2)\n",
    "fib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$ \\displaystyle \\mathrm{greek}({\\alpha}, {\\beta}, {\\gamma}, {\\Omega})\\triangleq {\\alpha}{\\beta} + \\Gamma\\left({{\\gamma}}\\right) + {\\Omega} $$"
      ],
      "text/plain": [
       "<latexify.core.with_latex.<locals>._LatexifiedFunction at 0x7fe8c0569f10>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Some math symbols are converted automatically.\n",
    "@latexify.with_latex\n",
    "def greek(alpha, beta, gamma, Omega):\n",
    "  return alpha * beta + math.gamma(gamma) + Omega\n",
    "greek"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### ❇️ Hope you enjoyed reading!! 📖 \n",
    "##### ❇️ follow → @akshay_pachaar  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "env_mld",
   "language": "python",
   "name": "env_mld"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
